<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form th:action="@{/car/update}" method="POST">
    <input type="hidden" name="carId" th:value="${ed.carId}">
    <p>
        车名：<input name="carName" type="text" readonly th:value="${ed.carName}">
    </p>
    <p>
        车价（元）：<input name="carPrice" type="text" th:value="${ed.carPrice}">
    </p>
    <p>
        里程：<input name="carMileage" type="text" th:value="${ed.carMileage}">
    </p>
    <p>
        购车时间：<input name="carBuyTime" type="text" th:value="${#dates.format(ed.carBuyTime,'yyyy-MM-dd')}">yyyy-MM-dd
    </p>
    <p>
        车型：<select name="carType">
        <option th:each="cartypes : ${cartypes}" th:selected="${ed.carType == cartypes.tid}"
                th:text="${cartypes.name}" th:value="${cartypes.tid}">
        </option>
    </select>
    </p>
    <p>
    <p>
        状态：
        <input type="radio" name="carStatus" value="0" th:checked="${ed.carStatus == 0}">在售
        <input type="radio" name="carStatus" value="1" th:checked="${ed.carStatus == 1}">已售
    </p>
    <p>
        <input type="submit" value="修改">
    </p>
</form>
</body>
<script src="/js/jquery.js"></script>
<script>
    $(document).ready(function() {
        $('#documentForm').submit(function(event) {
            // 取消默认的表单提交行为
            event.preventDefault();

            // 获取表单字段的值
            var carName = $('input[name="carName"]').val();
            var carPrice = $('input[name="carPrice"]').val();
            var carMileage = $('input[name="carMileage"]').val();
            var carBuyTime = $('input[name="carBuyTime"]').val();
            var carType = $('input[name="carType"]').val();
            var carStatus = $('input[name="carStatus"]').val();

            // 非空验证
            if (carName === '' || carPrice === '' || carMileage === '' || carBuyTime === '' || carType === '' || carStatus === '') {
                alert('所有字段都必须填写！');
                return;
            }

            // 日期格式验证
            var datePattern = /^\d{4}-\d{2}-\d{2}$/;
            if (!datePattern.test(carBuyTime)) {
                alert('购车时间必须按照yyyy-MM-dd的格式输入！');
                return;
            }

            // 如果通过验证，则提交表单
            this.submit();
        });
    });
</script>
</html>